// JavaScript Document

//图片等比例缩放及垂直居中
function resize(drawImage,fixw,fixh) {
    var w=drawImage.width;
	var h=drawImage.height;
    if(w>=fixw && h<=fixh){drawImage.width=fixw;drawImage.height=h/(w/fixw);}
    if(h>=fixh && w<=fixw){drawImage.height=fixh;drawImage.width=w/(h/fixh);}
	if(h>=fixh && w>=fixw){
		if(w/h >= fixw/fixh){drawImage.width=fixw;drawImage.height=h/(w/fixw);}
		else{drawImage.height=fixh;drawImage.width=w/(h/fixh);}
	}
	drawImage.style.marginTop = (fixh-drawImage.height)/2 + 'px';
}

$(function(){LinkUrl();});

var Crow,Cindex;
function LinkUrl(){
	var strUrl=window.location.href;      //当前页面URL
	var arrUrl=strUrl.split("/");         //按‘/’分割URL
	var strPage=arrUrl[arrUrl.length-1];  //取得URL最后的部分如"index.html"
	//检测地址后面是否带其它参数，一般以“？”链接
	var hasQ = /[0-9]+\?\w+$/;
	if(hasQ.test(strPage)){
	var addQ=strPage.split("?"); 
	var strPage=addQ[0];
	}

	var currId;
	var alla=$(".row").find("li").find("a");
	var al=alla.length;
	for(var i=0; i<al; i++){
	var eacha=alla.eq(i).attr("href");
	var eachar=eacha.split("/");
	var eachah=eachar[eachar.length-1];
		if(strPage == eachah){
		$(alla.eq(i)).css("border","solid 1px #f00");
		currId = $(alla.eq(i)).parent("li").parent("ul");
		Cindex=i;
		break;
		}
	}

	//图片定位及翻页
	$('#VideoBox .row').width(al*129+'px');
	$("#VideoBox").css('left', -(Cindex)*129+'px');
	if((al-Cindex) > 7){
		$('#ListSwitch .r').addClass('ac');
		var nex=$(alla.eq(Cindex+7)).attr("href");
		$(".r.ac").attr("href",nex);
	}
	if(Cindex>0){
		$('#ListSwitch .l').addClass('ab');
		if(Cindex>6){
			var pre=$(alla.eq(Cindex-7)).attr("href");
		} else {
			var pre=$(alla.eq(0)).attr("href");
		}
		$(".l.ab").attr("href",pre);
	}

	//左右换图
	var findul=currId;
	var nexta; var prea;
	var ullist=$("#VideoBox").find("ul");
	if(findul.next().length > 0){nexta=findul.next().find("a").attr("href");}
	else{nexta=ullist.first().find("a").attr("href");}
	if(findul.prev().length > 0){prea=findul.prev().find("a").attr("href");}
	else{prea=ullist.last().find("a").attr("href");}
	$("#Players").find(".PicL > a").attr("href",prea);
	$("#Players").find(".PicR > a").attr("href",nexta);
}

